<?php
namespace app\common\model;
use think\model\concern\SoftDelete;

class Matter extends TyModel {

    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $defaultSoftDelete = 0;

    //状态
    public function getStatusNameAttr($value,$data){
        $status = [0 => '未开始',1 => '已完成',2 => '进行中'];
        return $status[$data['status']];
    }

    //数据源类型
    public function getSourceNameAttr($value,$data){
        $status = [1 => '巡店',2 => '内部协同',3 => '推广工作',4 => '工作日志',5 => '活动开展',6 => '通知公告'];
        return $status[$data['source']];
    }

    //确认状态
    public function getConfirmStatusNameAttr($value,$data){
        $status = [0 => '未确认',1 => '已确认'];
        return $status[$data['confirm_status']];
    }

    //超时
    public function getOutTimeNameAttr($value,$data){
        $status = [0 => '未超时',1 => '已超时'];
        $now_time = date('Y-m-d H:i:s');
        
        if($data['status'] == 1){
            $mf_maps = [];
            $mf_maps[] = ['matterid','=',$data['id']];
            $mf_maps[] = ['action','=',101];
            $mf_detail = model('matter_flow')->get_detail($mf_maps,'id,c_time');
            if(!empty($mf_detail)){
                if($data['out_time'] > $mf_detail['c_time']){
                    $key = 0;
                }else{
                    $key = 1;
                }
            }else{
                $key = 1;
            }
        }else{
            if($data['out_time'] > $now_time){
                $key = 0;
            }
            if($data['out_time'] <= $now_time){
                $key = 1;
            }
        }
        //halt($key);
        return $status[$key];
    }
}